#include "MappingResult.h"
CMappingResult::CMappingResult(void)
{
    this->initialization();
}

CMappingResult::CMappingResult(CAlignmentsQ& aQue, unsigned int uiReadLength = 0)
{
    initialization();
    this->uiReadLength = uiReadLength;
    this->uiDiff = aQue.MinDiff; //This is the minimum distance of mappings
    this->MultipleMappedNo = aQue.load;
    myStrCpy(this->QNAME, aQue.tag, FILENAME_MAX);
}

CMappingResult::~CMappingResult(void)
{
    ;
}

CMappingResult& CMappingResult::operator=(const CMappingResult& m)
{
    if (this != &m) {  // make sure not same object
        myStrCpy(this->QNAME, m.QNAME, FILENAME_MAX);
        this->FLAG = m.FLAG;
        this->strand = m.strand;
        myStrCpy(this->RNAME, m.RNAME, FILENAME_MAX);
        this->uiPOS = m.uiPOS;
        this->MAPQ = m.MAPQ;
        myStrCpy(this->CIGAR, m.CIGAR, FILENAME_MAX);
        this->uiSkippedLength = m.uiSkippedLength;
        this->uiSkippedPos = m.uiSkippedPos;
        myStrCpy(this->MRNM, m.MRNM, FILENAME_MAX);
        this->uiMPOS = m.uiMPOS;
        this->ISIZE = m.ISIZE;
        myStrCpy(this->caRead, m.caRead, READ_BUFFER_SIZE);
        myStrCpy(this->QScores, m.QScores, READ_BUFFER_SIZE);
        myStrCpy(this->revQScores, m.revQScores, READ_BUFFER_SIZE);
        myStrCpy(this->rawScores, m.rawScores, READ_BUFFER_SIZE);
        myStrCpy(this->caRef, m.caRef, READ_BUFFER_SIZE);
        myStrCpy(this->TAG, m.TAG, READ_BUFFER_SIZE);
        this->SNPtype = m.SNPtype;
        myStrCpy(this->caRef, m.caRef, READ_BUFFER_SIZE);
        this->mismatchScore = m.mismatchScore;
        this->uiDiff = m.uiDiff;
        this->uiReadLength = m.uiReadLength;

        this->matchScoreL = 0;  // For spliced alignment
        this->matchScoreR = 0; // For spliced alignment
        this->MEMES = 0;
    }
    return *this;    // Return ref for multiple assignment
}//end operator=

void CMappingResult::initialization(void)
{
    this->QNAME[0] = '\0';
    this->FLAG = 0;
    this->strand = '+';
    this->RNAME[0] = '\0';
    this->uiPOS = 0;
    this->MAPQ = 0;
    this->CIGAR[0] = '\0';
    this->uiSkippedLength = 0;
    this->uiSkippedPos = 0;
    this->MRNM[0] = '\0';
    this->uiMPOS = 0;
    this->ISIZE = 0;
    this->caRead[0] = '\0';
    this->QScores[0] = '\0';
    this->revComRead[0] = '\0';
    this->revQScores[0] = '\0';
    this->rawScores[0] = '\0';
    this->TAG[0] = '\0';
    this->uiDiff = 0;
    this->SNPtype = ' ';
    this->caRef[0] = '\0';
    this->mismatchScore = 0;
    this->uiReadLength = 0;
}

// replace a read's alignment with another its mapping
bool CMappingResult::upgrade(const CMappingResult& m)
{
    if (this != &m) {  // make sure not same object
        this->FLAG = m.FLAG;
        this->strand = m.strand;
        strcpy(this->RNAME, m.RNAME);
        this->uiPOS = m.uiPOS;
        this->MAPQ = m.MAPQ;
        strcpy(this->CIGAR, m.CIGAR);
        this->uiSkippedLength = m.uiSkippedLength;
        this->uiSkippedPos = m.uiSkippedPos;
        this->ISIZE = m.ISIZE;
        if (this->strand == '+' && m.strand == '-') {
            strcpy(this->revComRead, m.QScores);
            strcpy(this->revQScores, m.revQScores);
        }
        strcpy(this->TAG, m.TAG);
        this->SNPtype = m.SNPtype;
        strcpy(this->caRef, m.caRef);
        this->mismatchScore = m.mismatchScore;
        this->uiDiff = m.uiDiff;
    }
    return(true);
}
